﻿<common:LayoutAwarePage
    x:Name="pageRoot"
    x:Class="RK.Store.MetroSnake.UI.HighscorePage"
    DataContext="{Binding DefaultViewModel, RelativeSource={RelativeSource Self}}"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:RK.Store.MetroSnake.UI"
    xmlns:common="using:RK.Store.MetroSnake.Common"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d">

    <Page.Transitions>
        <TransitionCollection>
            <RepositionThemeTransition />
            <EntranceThemeTransition />
        </TransitionCollection>
    </Page.Transitions>

    <Grid Style="{StaticResource LayoutRootStyle}"
          Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="140" />
            <RowDefinition Height="60" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="120" />
            <ColumnDefinition Width="*" />
        </Grid.ColumnDefinitions>

        <!-- The background of this page -->
        <Rectangle
                Grid.RowSpan="3" Grid.ColumnSpan="2">
            <Rectangle.Fill>
                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                    <GradientStop Offset="0" Color="#CCCFCFCF" />
                    <GradientStop Offset="1" Color="#CC6B6B6B" />
                </LinearGradientBrush>
            </Rectangle.Fill>
        </Rectangle>
        <Rectangle
                Grid.RowSpan="1" Grid.ColumnSpan="2"
                Fill="#00CBFF" />

        <!-- Back button and page title -->
        <Grid Grid.ColumnSpan="2">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition Width="*" />
            </Grid.ColumnDefinitions>
            <Button x:Name="backButton" Click="GoBack" IsEnabled="{Binding Frame.CanGoBack, ElementName=pageRoot}" Style="{StaticResource BackButtonStyle}" />
            <TextBlock x:Name="pageTitle" Grid.Column="1" Text="{StaticResource AppName}" Style="{StaticResource PageHeaderTextStyle}" />
            <TextBlock x:Uid="HighscoreSubtitle" Grid.Column="1" Text="Highscore" Style="{StaticResource SubheaderTextStyle}" />
        </Grid>

        <!-- The header row for the list view -->
        <Grid Grid.Column="1" Grid.Row="1"
              Margin="0,10,50,0" VerticalAlignment="Bottom">
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="50" />
                <ColumnDefinition Width="*" />
                <ColumnDefinition Width="100" />
                <ColumnDefinition Width="350" />
            </Grid.ColumnDefinitions>

            <TextBlock x:Uid="HighScorePlayerName"
                       Grid.Column="1" Style="{StaticResource GroupHeaderTextStyle}"
                       FontWeight="Bold"
                       Text="Player Name" />
            <TextBlock x:Uid="HighScorePoints"
                       Grid.Column="2" Style="{StaticResource GroupHeaderTextStyle}"
                       FontWeight="Bold" HorizontalAlignment="Center"
                       Text="Points" />
            <TextBlock x:Uid="HighScoreDate"
                       Grid.Column="3" Style="{StaticResource GroupHeaderTextStyle}"
                       FontWeight="Bold" HorizontalAlignment="Center"
                       Text="Date" />
        </Grid>

        <!-- The list view containing all data-->
        <ListView Name="LstHighScore"
                  Grid.Column="1" Grid.Row="2"
                  Margin="0,50,50,50"
                  ItemsSource="{Binding Path=GameScores}">
            <ListView.ItemContainerStyle>
                <Style TargetType="ListViewItem">
                    <Setter Property="HorizontalContentAlignment" Value="Stretch" />
                </Style>
            </ListView.ItemContainerStyle>

            <ListView.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="50" />
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="100" />
                            <ColumnDefinition Width="350" />
                        </Grid.ColumnDefinitions>

                        <StackPanel Grid.Column="0" Orientation="Horizontal">
                            <TextBlock Style="{StaticResource GroupHeaderTextStyle}"
                                       Text="{Binding Path=ScoreIndex}" />
                            <TextBlock Style="{StaticResource GroupHeaderTextStyle}"
                                       Text="." />
                        </StackPanel>

                        <TextBlock Grid.Column="1" Text="{Binding Path=PlayerName}"
                                   Style="{StaticResource GroupHeaderTextStyle}" />
                        <TextBlock Grid.Column="2" Text="{Binding Path=TotalScore}"
                                   Style="{StaticResource GroupHeaderTextStyle}"
                                   HorizontalAlignment="Center" />
                        <TextBlock Grid.Column="3" Text="{Binding Path=DateFormatted}"
                                   Style="{StaticResource GroupHeaderTextStyle}"
                                   HorizontalAlignment="Center" />
                    </Grid>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

        <VisualStateManager.VisualStateGroups>

            <!-- Visual states reflect the application's view state -->
            <VisualStateGroup x:Name="ApplicationViewStates">
                <VisualState x:Name="FullScreenLandscape" />
                <VisualState x:Name="Filled" />

                <!-- The entire page respects the narrower 100-pixel margin convention for portrait -->
                <VisualState x:Name="FullScreenPortrait">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource PortraitBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>

                <!-- The back button and title have different styles when snapped -->
                <VisualState x:Name="Snapped">
                    <Storyboard>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="backButton" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedBackButtonStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                        <ObjectAnimationUsingKeyFrames Storyboard.TargetName="pageTitle" Storyboard.TargetProperty="Style">
                            <DiscreteObjectKeyFrame KeyTime="0" Value="{StaticResource SnappedPageHeaderTextStyle}" />
                        </ObjectAnimationUsingKeyFrames>
                    </Storyboard>
                </VisualState>
            </VisualStateGroup>
        </VisualStateManager.VisualStateGroups>
    </Grid>
</common:LayoutAwarePage>